<?php
namespace Home\Controller;
use Think\Log;

/**
 * Created by PhpStorm.
 * User: lazycao
 * Date: 2017/11/27 0027
 * Time: 10:10
 */
class GameController extends AuthController {
    function index($p = 1){
        $where = array();
        $nickname = I('get.nickname');
        $date = I('get.date');
        if('' !== $date){
            if(false !== strpos($date,'+-+')){
                $date = explode("+-+",$date);

            }else{
                $date = explode(" - ",$date);

            }
            $start_date = $date[0];
            $end_date = $date[1];
            if($start_date !== date('Y-m-d') ){
                $where['gr.date'] = array('between',array($start_date,date('Y-m-d H:i:s',strtotime($end_date)+3600*24)));
            }
        }

        if('' !== $nickname){
            $where['nickname'] = $nickname;
        }
        $gameObj = M('GameRecord as gr');
        $page_limit = 20;
        $list = $gameObj
            ->join('inner join wxg_users as u on gr.user_id = u.id')
            ->page($p.','.$page_limit)
            ->order('gr.id desc')
            ->where($where)
            ->field('*,gr.date as date')
            ->select();
        $this->assign('list',$list);// 赋值数据集

        $count      = $gameObj
                    ->join('inner join wxg_users as u on gr.user_id = u.id')
                    ->where($where)
                    ->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,$page_limit);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出

        $this->display();
    }
    function all(){
        $this->display();
    }
    function edit(){
        $this->display();
    }
    function playTime(){
        $data['play_time'] = I('post.playTime','','intval');
        $data['game_code'] = 'game1';
        $data['date'] = date('Y-m-d H:i:s',time());
        $data['user_id'] = I('post.id','','intval');
        Log::write('关闭提交数据'.json_encode($data));

        exit(json_encode($data));
    }
}
